using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using BA.DAL;
using Microsoft.VisualBasic;

namespace BlazeApps.Library.TreeViews
{
    public class TreeViewNodes : Base
    {
        private BA.DAL.DBUtility DAL = new BA.DAL.DBUtility();
        private Procedures Procs = new Procedures();

        public enum TreeType
        {
            ResourceTree = 0,
            MenuTree = 1,
            CategoriesTree = 2,
            UserTree = 3,
			NotSet = 4
        }

        public DataSet GetTreeParent(TreeType Type, Guid UserID)
        {
            if (Type == TreeType.ResourceTree)
            {
                DAL.CreateDBObjects(ConnectionString, Provider);
                return DAL.GetDataSet(Procs.ListTreeParent.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
            }
            else if(Type == TreeType.MenuTree)
            {
                DAL.CreateDBObjects(ConnectionString, Provider);
                return DAL.GetDataSet(Procs.ListMenuParent.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
            }
            else if (Type == TreeType.UserTree)
            {
                DAL.CreateDBObjects(ConnectionString, Provider);

                DAL.AddParameter("@userid", UserID);

                return DAL.GetDataSet(Procs.ListTreeParentByUserID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
            }
            else
            {
                return null;
            }
        }

        public DataSet GetTreeChild(string ParentNodeID, TreeType Type, Guid UserID)
        {
            if (Type == TreeType.ResourceTree)
            {
                DAL.CreateDBObjects(ConnectionString, Provider);

                DAL.AddParameter("@parentnodeid", ParentNodeID);
                return DAL.GetDataSet(Procs.ListTreeChildByParentID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
            }
            else if (Type == TreeType.MenuTree)
            {
                DAL.CreateDBObjects(ConnectionString, Provider);

                DAL.AddParameter("@parentnodeid", ParentNodeID);
                return DAL.GetDataSet(Procs.ListMenuChildByParentID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
            }
            else if (Type == TreeType.UserTree)
            {
                BA.DAL.DBUtility DAL = new BA.DAL.DBUtility();
                DAL.CreateDBObjects(ConnectionString, Provider);

                DAL.AddParameter("@userid", UserID);
                DAL.AddParameter("@parentnodeid", ParentNodeID);

                return DAL.GetDataSet(Procs.ListTreeChildByParentIDUserID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
            }
            else
            {
                return null;
            }
        }
    }
}
